#include <mutex>
#include <iostream>

class Singleton
{
public:
	static Singleton* getInstance();
	void sayHello();

private:
	static Singleton* sInstance;
	static std::once_flag flag;
	Singleton();
	Singleton(const Singleton&);
	Singleton& operator=(const Singleton&);
	~Singleton();
};

Singleton* Singleton::sInstance = NULL;
std::once_flag Singleton::flag;

Singleton* Singleton::getInstance()
{
	std::call_once(flag, [](){
		sInstance = new Singleton();}
		);
	return sInstance;
}

Singleton::Singleton(){}

Singleton::Singleton(const Singleton& singleton){}

Singleton& Singleton::operator=(const Singleton& singleton)
{
	return *this;
}

void Singleton::sayHello()
{
	std::cout<<"hello, world!"<<std::endl;
}

Singleton::~Singleton(){}
	
int main(int argc, char* argv[])
{
	Singleton* instance = Singleton::getInstance();
	instance->sayHello();
	return 0;
}
